<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text" id="i1">
<input type="button" value="平方" onclick="f()">
<div>结果:<span></span></div>
<script>
    function f() {
        let i = document.querySelector("#i1");
        let pf = document.querySelector("span");
        //"a"*"a"  NaN*NaN = NaN  不是一个数
        //isNaN()判断变量是否为NaN
        if(isNaN(i.value)){
            pf.innerText="输入有误！";
            return;
        }
        /*pf.innerText = i.value*i.value;*/
        //当两个字符串进行-*/运算时会自动转成数值,进行+运算是拼接
        /*pf.innerText=i.value*1+i.value*1;*/
        //parseFloat()将字符串转成整数或小数
        pf.innerText=parseFloat(i.value)+parseFloat(i.value);
    }
</script>
</body>
</html>